package com.libweb.servlet;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.libweb.model.dao.MemberDao;
import com.libweb.model.dto.Member;

@WebServlet("/member/editform.action")
public class MemberEditFormServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		String memberId = request.getParameter("memberid");
		if (memberId == null || memberId.length() == 0) {
			response.sendRedirect("/libweb/home.action");
			return;
		}
		
		MemberDao dao = new MemberDao();
		Member member = dao.getMemberById(memberId);
		
		if (member == null) {
			response.sendRedirect("/libweb/home.action");
			return;
		}
		
		request.setAttribute("member", member);
		
		RequestDispatcher dispatcher = 
			request.getRequestDispatcher("/WEB-INF/views/member/editform.jsp");

		dispatcher.forward(request, response);
		
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
